import {
    APIS
} from "../../utils/api";
import {
    get
} from "../../utils/request";

Page({
    data: {
        used: 0,
        currShop: {},
        ruleList: [],
        cnNum: ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
    },
    onLoad() {
        const currShop = wx.getStorageSync('currShop');
        this.setData({
            currShop
        })
    },
    onShow() {
        this.getRules()
    },
    handleShopChange(e) {
        let currShop = e.detail;
        this.setData({
            currShop
        })
        this.getRules();
    },
    getRules() {
        const {
            currShop
        } = this.data;
        get(APIS.rulesegment, {
            shop: currShop.id
        }).then(res => {
            const ruleList = res.data;
            ruleList.forEach(fees => {
                let cLen = fees.table.cards.length;
                let bLen = fees.table.balls.length;
                if (cLen) {
                    fees.table.cards[cLen - 1].isLast = true;
                }
                else if (bLen) {
                    fees.table.balls[bLen - 1].isLast = true;
                }
            })
            this.setData({
                ruleList
            });
        })
    },

    handleJumpCreate() {
        wx.navigateTo({
          url: `/pages/tablenew/index?shop=${this.data.currShop.id}&action=new`,
        })
    },
    handleDetail(e) {
        let {item} = e.target.dataset;
        wx.navigateTo({
          url: `/pages/tabledetail/index?id=${item.id}&shop=${item.shop}`,
        })
    }
})